package com.lili.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.model.order.entity.order.Order;
import com.lili.model.order.entity.PageMap;
import com.lili.order.mapper.order.OrderMapper;
import com.lili.order.service.order.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    /**
     *   增加
     */
    public  int save(Order order){
        return orderMapper.insert(order);
    }

    @Override
    public int deleteBySn(Serializable id) {
        return orderMapper.deleteBySn(id);
    }

    /**
     *   删除
     */
    @Override
    public int deleteById(Serializable id) {

        return orderMapper.deleteById(id);
    }
    /**
     *   更改
     */
    @Override
    public int updateById(Order order) {

        return orderMapper.updateById(order);
    }

    /**
     *   查询
     */
    @Override
    public List<Order> getAllOrders() {
        return orderMapper.selectList(null);
    }
    @Override
    public  Page<Order> getAllOrdersByPage(Map map) {
        QueryWrapper<Order> wrapper=new QueryWrapper<>();
        PageMap pageMap=new PageMap(map);

        wrapper.eq("delete_flag",0);
        if(map.containsKey("sn")){
         wrapper.like("sn",map.get("sn"));
        }
        if(map.containsKey("memberName")){
            wrapper.like("member_name",map.get("memberName"));
        }
        if(map.containsKey("orderType")){
            wrapper.like("order_type",map.get("orderType"));
        }
        if(map.containsKey("createTime")){
            wrapper.ge("create_time",map.get("createTime"));
        }
        if(map.containsKey("orderStatus")){
            wrapper.like("order_status",map.get("orderStatus"));
        }
        if(map.containsKey("isEntity")){
            wrapper.like("is_entity",map.get("isEntity"));
        }
        if(map.containsKey("storeId")){
            wrapper.like("store_id",map.get("storeId"));
        }
        Page<Order> page = new Page<>(pageMap.getPage(), pageMap.getPageSize());
        orderMapper.selectPage(page,wrapper);

        return page;
    }













}
